<template>
  <el-form ref="formRef" :model="numberValidateForm" label-width="auto" class="demo-ruleForm">
    <div class="cpro-points">
      <cproPublic title="项目总积分" :show-stat="true">
        <template v-slot:content>
          <el-form-item
            prop="points"
            class="item"
            :rules="[{ required: true, message: '必须填写项目积分' }]"
          >
            <el-input
              class="input"
              v-model.number="numberValidateForm.points"
              type="number"
              autocomplete="on"
              placeholder="请输入当前项目包含的总积分"
            />
          </el-form-item>
        </template>
      </cproPublic>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
import { ElMessage } from 'element-plus'
import cproPublic from '@/components/creat-projects/cpro-public.vue'
import { ref, reactive } from 'vue'
const numberValidateForm = reactive({ points: '' })
const emit = defineEmits(['updateScore'])

const formRef = ref<FormInstance>()
//父组件调用提交的方法
const upLoadPoints = (): Boolean => {
  //积分填写不规范报错
  if (!numberValidateForm.points) {
    ElMessage({
      showClose: true,
      message: '请填写项目总积分',
      type: 'error'
    })
    return false
  } else if (Number(numberValidateForm.points) <= 0) {
    ElMessage({
      showClose: true,
      message: '积分必须大于0',
      type: 'error'
    })
    return false
  } else {
    emit('updateScore', numberValidateForm.points)
    return true
  }
}
defineExpose({ upLoadPoints })
</script>

<style scoped>
.cpro-points {
  .item {
    margin: 0 0 0 8px;
  }
  .input {
    border: 1px solid #e4e4e4;
    border-radius: 5px;
    width: 1069px;
    height: 40px;
    line-height: 40px;
    font-size: 13px;
  }
}
</style>
